package itsm.isperp.module.dto.app;

import itsm.isperp.framework.domain.IRole;
import itsm.isperp.framework.security.domain.MemberRole;
import itsm.isperp.module.entity.app.AppRole;
import itsm.isperp.module.entity.app.AppUser;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang.NullArgumentException;
import org.apache.commons.lang3.StringUtils;

/**
 * 
 * 系统用户&角色传输实体
 * 
 * @author lizx
 * @date 2013-2-23
 * @version V1.0
 */
public class AppUserRoleDTO implements MemberRole {

	protected String name;

	protected String password;

	protected Date availableDate;

	protected List<? extends IRole> roles;

	private String fullname;

	private AppUserType userType;

	public AppUserRoleDTO(AppUser appUser) throws NullArgumentException {
		if (appUser == null)
			throw new NullArgumentException("用户对象不能为空");

		if (StringUtils.isEmpty(appUser.getName())
				&& StringUtils.isEmpty(appUser.getFullname()))
			throw new NullArgumentException("用户名及姓名不能为空");

		this.name = appUser.getName();
		this.password = appUser.getPassword();
		this.fullname = appUser.getFullname();

	}

	/**
	 * 构造一个系统用户数据传输对象
	 * 
	 * @param name
	 *            用户名（不能为空）
	 * @param password
	 *            密码（不能为空）
	 * @param fullname
	 *            姓名（不能为空）
	 * @param availableDate
	 *            有效期（为空表示永久帐号）
	 * @param userType
	 *            用户类型（不能为空）
	 * @param roles
	 *            角色
	 * @throws Exception
	 *             如果用户名或者密码为空
	 */
	public AppUserRoleDTO(String name, String password, String fullname,
			Date availableDate, AppUserType userType, List<AppRole> roles)
			throws NullArgumentException {

		if (StringUtils.isEmpty(name) && StringUtils.isEmpty(fullname))
			throw new NullArgumentException("用户名及姓名不能为空");

		this.name = name;
		this.password = password;
		this.fullname = fullname;
		this.availableDate = availableDate;
		this.userType = userType;
		this.roles = roles;

	}

	public String getFullname() {
		return fullname;
	}

	public AppUserType getUserType() {
		return userType;
	}

	public String getName() {
		return name;
	}

	@Override
	public String getPassword() {
		return password;
	}

	@Override
	public List<? extends IRole> getRoles() {
		return roles;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public void setRoles(List<? extends IRole> roles) {
		this.roles = roles;
	}

	public void setUserType(AppUserType userType) {
		this.userType = userType;
	}

	@Override
	public String getMemberName() {
		return this.name;
	}

	@Override
	public void setUserName(String name) {
		this.name = name;
	}

}
